from django.db import models

class AppInfo(models.Model):
    version = models.CharField('版本号', max_length=20)
    build_number = models.CharField('构建号', max_length=20)
    release_notes = models.TextField('更新说明')
    force_update = models.BooleanField('强制更新', default=False)
    created_at = models.DateTimeField('创建时间', auto_now_add=True)
    
    class Meta:
        verbose_name = '应用信息'
        verbose_name_plural = '应用信息'
    
    def __str__(self):
        return f"v{self.version} ({self.build_number})"

class Agreement(models.Model):
    title = models.CharField('标题', max_length=100)
    content = models.TextField('内容')
    version = models.CharField('版本', max_length=20)
    effective_date = models.DateField('生效日期')
    
    class Meta:
        verbose_name = '用户协议'
        verbose_name_plural = '用户协议'
    
    def __str__(self):
        return f"{self.title} v{self.version}"

class PrivacyPolicy(models.Model):
    title = models.CharField('标题', max_length=100)
    content = models.TextField('内容')
    version = models.CharField('版本', max_length=20)
    effective_date = models.DateField('生效日期')
    
    class Meta:
        verbose_name = '隐私政策'
        verbose_name_plural = '隐私政策'
    
    def __str__(self):
        return f"{self.title} v{self.version}"

#后台

# models.py (新增内容)
class Banner(models.Model):
    title = models.CharField('标题', max_length=100)
    image = models.ImageField('图片', upload_to='banners/')
    link = models.URLField('跳转链接', blank=True)
    is_active = models.BooleanField('是否启用', default=True)
    display_order = models.PositiveIntegerField('显示顺序', default=0)
    created_at = models.DateTimeField('创建时间', auto_now_add=True)
    
    class Meta:
        verbose_name = '首页Banner'
        verbose_name_plural = '首页Banner'
        ordering = ['display_order']
    
    def __str__(self):
        return self.title

class PlatformSettings(models.Model):
    service_fee_rate = models.DecimalField('平台服务费率(%)', max_digits=5, decimal_places=2, default=10.00)
    min_withdraw_amount = models.DecimalField('最低提现金额', max_digits=10, decimal_places=2, default=100.00)
    updated_at = models.DateTimeField('更新时间', auto_now=True)
    
    class Meta:
        verbose_name = '平台设置'
        verbose_name_plural = '平台设置'
    
    def __str__(self):
        return f"平台设置(服务费:{self.service_fee_rate}%)"

class SMSTemplate(models.Model):
    TEMPLATE_TYPES = [
        ('REGISTER', '注册验证码'),
        ('LOGIN', '登录验证码'),
        ('RESET_PWD', '重置密码'),
        ('ORDER_CONFIRM', '订单确认'),
    ]
    
    template_type = models.CharField('模板类型', max_length=20, choices=TEMPLATE_TYPES, unique=True)
    template_id = models.CharField('模板ID', max_length=50)
    template_content = models.TextField('模板内容')
    is_active = models.BooleanField('是否启用', default=True)
    
    class Meta:
        verbose_name = '短信模板'
        verbose_name_plural = '短信模板'
    
    def __str__(self):
        return f"{self.get_template_type_display()}模板"

class CustomerService(models.Model):
    phone = models.CharField('客服电话', max_length=20)
    wechat = models.CharField('微信客服', max_length=50, blank=True)
    qq = models.CharField('QQ客服', max_length=20, blank=True)
    work_time = models.CharField('工作时间', max_length=100, default='9:00-18:00')
    
    class Meta:
        verbose_name = '客服设置'
        verbose_name_plural = '客服设置'
    
    def __str__(self):
        return f"客服设置({self.phone})"